<template>
  <div class="detail-nav">
    <NavBar>
      <!-- 返回按钮 -->
      <div slot="left" class="back" @click="backClick">
        <img src="~assets/img/common/back.svg" alt="">
      </div>
      <!-- 标题 -->
      <div slot="center" class="detial-nav-bar">
        <div v-for="(item, index) in title" 
        :key="index"
        @click="titleClick(index)"
        :class="{active: index === currentIndex}"
        class="title">{{item}}</div>
      </div>
    </NavBar>
  </div>
</template>

<script>
import NavBar from 'components/common/navbar/NavBar';
export default {
  name: 'detailNavBar',
  data() {
    return{
      title: ['商品', '参数', '评论', '推荐'],
      currentIndex: 0
    }
  },
  components: {
    NavBar
  },
  methods: {
    titleClick(index) {
      this.currentIndex = index;
      this.$emit('detailNavClick', index);
    },
    backClick() {
      this.$router.back();
    }
  }
}
</script>

<style scoped>
  /* 详情页导航栏内容 */
  .detial-nav-bar{
    display: flex;
    font-size: 14px;
  }

  /* 详情页返回内容 */
  .back{
    margin-top: 6px;
  }
  .back img{
    width: 22px;
  }
  /* 详情页标题内容 */
  .title{
    flex: 1;
  }
  .active{
    color: var(--color-high-text);
  }
</style>